{* $Id$ *}
{include_core file="admin/lib/header.html" title="冰川时代5海报任务管理"}
<div class="page-header border-bottom clearfix">
    <h2 class="left">冰川时代5海报任务管理<span>任务列表</span></h2>
    <a href="{AnUrl("glacial_era/admin/export")}" class="btn btn-success btn-sm right" target="_blank">导出EXCEL</a>
    <!--<a href="{AnUrl("glacial_era/admin/download")}?topic_name=glacial_era" class="btn btn-success btn-sm right" target="_blank">图片打包下载</a>-->
</div>

<div class="search-form js_advancedForm">
    <form action="{AnUrl("glacial_era/admin")}" method="get" class="js_focusSearchForm">
        <p>
            <label for="" class="search-f-label" >合伙人名称：</label>
            <input type="text" class="search-f-ipt1" style="height:20px" name="search_filter[realname]" value="{$search_filter.realname}" id="realname">
        </p>
        <p>
            <label for="" class="search-f-label">店铺名称：</label>
            <input type="text" class="search-f-ipt1"  style="height:20px" name="search_filter[title]" value="{$search_filter.title}" id="store_name">
        </p>
        <p>
            <label for="" class="search-f-label">地区筛选：</label>
            <select name="search_filter[province_id]"  class="js_provinceList" style="width:120px;">
                <option value="0" selected="selected">请选择省份</option>
            </select>
            <select name="search_filter[city_id]"  class="js_cityList" style="width:120px;{if !$search_filter.city_id || $search_filter.city_id == '000000'}display:none;{/if}">
                <option value="0">请选择城市</option>
            </select>
            <select name="search_filter[district_id]" class="js_countyList" style="width:120px;{if !$search_filter.district_id || $search_filter.district_id == '000000'}display:none;{/if}">
                <option value="0">请选择区(县)</option>
            </select>
        </p>
        <p><label for="" class="search-f-label"></label><button type="submit" class="btn btn-success btn-xs js_searchBtn">搜索</button></p>
  </form>
</div>

<!--按状态检索-->
<div class="list-table-filters">
    <p>
        <span class="label label-info">按状态</span>
        <a href="{AnUrl("glacial_era/admin?{URLTracker::set("status", -1)}")}" {if $status == -1} class="label label-primary" {else} class="label label-default" {/if}>全部</a>
        {foreach glacial_era_config::$status as $k => $v}
        <a href="{AnUrl("glacial_era/admin?{URLTracker::set("status", $k)}")}" {if $status == $k} class="label label-primary" {else} class="label label-default" {/if}>{$v}</a>
        {/foreach}
    </p>
</div>

<table class="list-table">
    <thead>
        <tr>
            <th>ID</th>
            <th>门店头图</th>
            <th>上传时间</th>
            <th>照片</th>
            <th>合伙人id</th>
            <th>合伙人名称</th>
            <th>店铺id</th>
            <th>店铺名称</th>
            <th>店铺分支</th>
            <th>状态</th>
            <th>操作</th>
        </tr>
    </thead>
    <tbody>
        {foreach $photo_list as $k=>$v}
        <tr id="dataList{$v.id}" {if $k%2 == 1} class="bg-gray"{/if}>
            <td>{$v.id}</td>
            <td>
                <a href="{$v.cover}" target="_blank">
                    <img width="100" height="80" src="{$v.cover}" />
                </a>
            </td>
            <td>{$v.upload_time}</td>
            <td>
                <a href="{$v.src}" target="_blank">
                    <img width="100" height="80" src="{$v.src}" />
                </a>
            </td>
            <td>{$v.parent_id}</td>
            <td>{$v.realname}</td>
            <td>{$v.store_id}</td>
            <td>{$v.title}</td>
            <td>{$v.title_branch}</td>
            <td>
                {if $v.status == 0}
                待审核
                {elseif $v.status == 1}
                已审核
                {elseif $v.status == 2}
                已驳回
                {/if}
            </td>
            <td>
            {if $v.status == 0}
            <a href="{AnUrl("glacial_era/admin/change_status?id={$v.id}&status=2")}" class="btn btn-warning btn-xs js_changeStatus"><i class="icon-trash icon-white"></i>驳回</a>
            <a href="{AnUrl("glacial_era/admin/change_status?id={$v.id}&status=1")}" class="btn btn-info btn-xs js_changeStatus"><i class="icon-trash icon-white"></i>审核通过</a>
            {elseif $v.status == 1}
            <a href="{AnUrl("glacial_era/admin/change_status?id={$v.id}&status=2")}" class="btn btn-warning btn-xs js_changeStatus"><i class="icon-trash icon-white"></i>驳回</a>
            {elseif $v.status == 2}
            <a href="{AnUrl("glacial_era/admin/change_status?id={$v.id}&status=1")}" class="btn btn-info btn-xs js_changeStatus"><i class="icon-trash icon-white"></i>通过</a>
            {/if}
            </td>
        </tr>
        {foreachelse}
        <tr><td class="txtleft" colspan="11">暂无数据</td></tr>
        {/foreach}
    </tbody>
</table>
<script type="text/javascript">
    //初始化省份列表
    $.ajax({
        url: 'area/admin/ajax_get_provinces',
        type: 'get',
        dataType: 'json',
        success: function(province_list) {
            for (var i in province_list) {
                var opt = $('<option value="' + province_list[i].area_code + '">' + province_list[i].area + '</option>');
                $('.js_provinceList').append(opt);
            }

            {if $search_filter.province_id}
                $('.js_provinceList').val("{$search_filter.province_id}");
                $('.js_provinceList').change();
                {if $search_filter.city_id}
                    $('.js_cityList').val("{$search_filter.city_id}")
                    $('.js_cityList').change();
                {/if}
            {/if}
        }
    });

    //省份改变时触发
    $('.js_provinceList').change(function() {
        //没选择省份时清空城市和县数据
        if ($(this).val() == '0') {
            $('.js_cityList').slideUp();
            $('.js_countyList').slideUp();
            $('.js_cityList').empty();
            $('.js_countyList').empty();
            return false;
        }

        //城市显示
        var province = $(this).val();
        $('.js_cityList').slideDown();
        $('.js_cityList').empty();
        $('.js_cityList').append('<option value="0">请选择城市</option>');

        //县隐藏
        $('.js_countyList').slideUp();
        $('.js_countyList').empty();
        $('.js_countyList').append('<option value="0">请选择区(县)</option>');

        $.ajax({
            url: 'area/admin/ajax_get_citys?province_code=' + province,
            success: function(city_list) {
                for (var i in city_list) {
                    var opt = $('<option value="' + city_list[i].area_code + '">' + city_list[i].area + '</option>');
                    $('.js_cityList').append(opt);
                }
            },
            type: 'get',
            dataType: 'json',
            async: false
        });
    });

    //城市改变时触发
    $('.js_cityList').change(function() {
        //县显示
        $('.js_countyList').slideDown();
        $('.js_countyList').empty();
        $('.js_countyList').append('<option value="0">请选择区(县)</option>');

        //获取省份的key和值
        var province_code = $('.js_provinceList').val();
        var pro_text = $('.js_provinceList').text();
        //获取城市的值
        var city_code = $(this).val();

        $.ajax({
            url: 'area/admin/ajax_get_countys?province_code=' + province_code + '&city_code=' + city_code,
            type: 'get',
            dataType: 'json',
            success: function(county_list) {
                for (var i in county_list) {
                    var opt = $('<option value="' + county_list[i].area_code + '">' + county_list[i].area + '</option>');
                    $('.js_countyList').append(opt);
                }

                {if $search_filter.district_id}
                    $('.js_countyList').val("{$search_filter.district_id}");
                {/if}
            }
        });
    });

    //导出海报任务
    $('#export').click(function() {
        var export_start_date =  $('#export_start_date').val();
        var export_end_date =  $('#export_end_date').val();

        $.ajax({
            url: 'glacial_era/admin/export',
            data: {
                'export_start_date': export_start_date,
                'export_end_date': export_end_date
            },
            success: function() {},
            type: 'post',
            dataType: 'json',
            async: false
        });
    });

    //更改状态
    $('.js_changeStatus').live('click', function(e) {
        e.preventDefault();
        e.stopPropagation();

        var notice = '确定执行此操作吗?';
        var clickObj = $(this);
        var url = clickObj.attr("href");

        showConfirm(notice, 1, function() {
            $.post(url, {}, function(data) {
                if (data.flag == 1) {
                    showMsg(data.message);
                    return false;
                }

                window.location.reload();
            }, 'json');
        });
    });
</script>
{include_core file="admin/lib/pager.html"}
{include_core file="admin/lib/footer.html"}